﻿namespace _01线性表
{
    internal class Program
    {
        static int N = 10;
        static int n = 0;
        static int[] array = new int[N];
        /// <summary>
        /// 初始化5个元素
        /// </summary>
        private static void Init()
        {
            for (int i = 0; i < N/2; i++)
            {
                array[i] = i+1;
            }
            n = N/2;
        }

        private static void  Insert(int k ,int value)
        {
            //判断插入位置
            if (k < 1 || k > n + 1)
            {
                Console.WriteLine("插入位置错误");
                return; 
            }
            for(int i = n; i >= k; i--)
            {
                array[i] = array[i - 1];
            }
            array[k-1] = value;
            n++;

        }

        private static void Delete(int k)
        {
            if (k < 1 || k > n)
            {
                Console.WriteLine("删除位置错误");
                return;
            }
            for (int i = k; i < n; i++)
            {
                array[i - 1] = array[i];
            }
            n--;
        }

        private static void Print()
        {
            for (int i = 0; i < n; i++)
            {
                Console.Write (array[i]+" ");
            }
            Console.WriteLine();
        }

        static void Main(string[] args)
        {
            Init();

            Print();
            
            Insert(6, 100);
            Print();

            Delete(6);
            Print();

            Console.Read();
        }
    }
}
